package com.more.offer.threadtest.futureTaskTest;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author pinoc
 * @date 2021/6/20
 * @description
 */
public class CallerTaskTest implements Callable<String> {
	@Override
	public String call() throws Exception {
		Thread.sleep(3000);
		return "hello";
	}

	public static void main(String[] args) {
		FutureTask<String> task = new FutureTask<>(new CallerTaskTest());
		new Thread(task).start();
		try {
			String s = task.get();
			System.out.println("future task result: " + s);
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
	}
}
